﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ExportToRTR.CApExportToRTRXmlWriter
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.Generic;
using System.Text;
using System.Xml;


namespace DnProcessSimulateCommands.ExportToRTR{

public class CApExportToRTRXmlWriter(string filename, Encoding encoding) : XmlTextWriter(filename, encoding)
{
  private Stack<string> m_elements = new Stack<string>();

  public Dictionary<string, int> Joints { get; set; } = new Dictionary<string, int>();

  public Dictionary<string, int> Links { get; set; } = new Dictionary<string, int>();

  private string CurrentElement
  {
    get => this.m_elements.Count != 0 ? this.m_elements.Peek() : "";
    set => this.m_elements.Push(value);
  }

  public new void WriteAttributeString(string localName, string value)
  {
    base.WriteAttributeString(localName, value);
    if (!(localName == "name"))
      return;
    if (this.CurrentElement == "joint")
    {
      this.Joints[value] = this.Joints.ContainsKey(value) ? this.Joints[value] + 1 : 1;
    }
    else
    {
      if (!(this.CurrentElement == "link"))
        return;
      this.Links[value] = this.Links.ContainsKey(value) ? this.Links[value] + 1 : 1;
    }
  }

  public new void WriteStartElement(string localName)
  {
    base.WriteStartElement(localName);
    this.CurrentElement = localName;
  }

  public override void WriteEndElement()
  {
    base.WriteEndElement();
    this.m_elements.Pop();
  }
}
